<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;

class UserGender extends AbstractTool
{
    protected function script()
    {
        $csrf_token=csrf_token();
        return <<<EOT
           var is_true=1;
    $("#validate").click(function(){
        swal({ 
  title: "门票号码验证", 
  text: "输入订单号码",
  type: "input", 
  showCancelButton: true, 
  closeOnConfirm: false, 
  animation: "slide-from-top", 
  inputPlaceholder: "输入订单号码" 
},
function(inputValue){ 
  if (inputValue === false) return false; 
  
  if (inputValue === "") { 
    swal.showInputError("你需要输入订单号！");
    return false 
  } 
  
  $.post('/administrator/order/'+inputValue+'/inspectTicket',{_token:'$csrf_token'},function(data){
        if(data.code=='error'){
               if(data.data){
                    swal.showInputError('<span style="color: red">'+data.message+'</span></br> 用户id:'+data.data.member.id+'</br>昵称:'+data.data.member.nickname+'</br>手机号:'+data.data.member.mobile);
                    return false;
               } 
           swal.showInputError(data.message);
           return false;     
        }
        if(data.code=='success'){
            swal({ 
  title: "订单查询成功", 
  text: data.message+'用户id:'+data.data.member.id+'昵称:'+data.data.member.nickname+'手机号:'+data.data.member.mobile+'身份证号:'+data.data.member.is_number+'门票名称:'+data.data.combo.title+'*'+data.data.total_num, 
  type: "success",
  showCancelButton: true, 
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "确定发放！", 
  cancelButtonText: "取消！",
  closeOnConfirm: false, 
  closeOnCancel: false	
},
function(isConfirm){ 
  if (isConfirm) { 
      
         if(is_true==0){
         return false;
         }
         is_true=0;
         $.post('/administrator/order/'+data.data.id+'/sendTicket',{_token:'$csrf_token'},function(res){
         is_true=1;
          if(res.code=='success'){
            swal("成功！", "门票发放成功! 门票名称:"+res.data,
"success"); 
     $.pjax.reload('#pjax-container');

          }
          
          if(res.code=='error'){
            swal("失败!",res.message,'error');
          }
            
         
         });
  } else { 
    swal("取消！", "已经取消发放",
"error"); 
  } 
});

        }
    
  });   
 
});
    
    
    });    
    

EOT;
    }

    public function render()
    {
        Admin::script($this->script());

        return view('administrator.tools.gender', compact('options'));
    }
}